#include "videoqualitysettingdialog.h"
#include "ui_videoqualitysettingdialog.h"

#include "encoderoption.h"
#include "option_def.h"

VideoQualitySettingDialog::VideoQualitySettingDialog(EncoderOption *o,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::VideoQualitySettingDialog),
    m_option(o)
{
    ui->setupUi(this);

    adjustSize();
    syncConfig(DirectionRead);
}

VideoQualitySettingDialog::~VideoQualitySettingDialog()
{
    delete ui;
    syncConfig(DirectionWrite);
}


void VideoQualitySettingDialog::on_buttonBox_accepted()
{


    accept();
}

void VideoQualitySettingDialog::on_buttonBox_rejected()
{
    reject();
}

void VideoQualitySettingDialog::syncConfig(SyncDirection d){
    switch(d){
    case DirectionRead:
    default:
	ui->inputBitrate->setValue(m_option->value(VIDEO_BITRATE,700).toInt());
	ui->btnKeepOriginal->setChecked(m_option->value(VIDEO_BITRATE_KEEP_ORIGIN,false).toBool());
    }
}

void VideoQualitySettingDialog::on_btnKeepOriginal_clicked(bool checked)
{
    ui->inputBitrate->setDisabled(checked);
}

void VideoQualitySettingDialog::onOptionValueChanged(const QString & key, const QVariant & v, QObject *obj){
    if (obj == this) return;

    if (key == VIDEO_BITRATE) {
	    ui->inputBitrate->setValue(v.toInt());
    }
}

